
/**
 * 级联选择框
 * 注：此处可能会添加多个，用props中的count来定义name名称
 * add by lifenping
 * on 2020.02.27
 */
import React from 'react';
import { Form, Cascader } from 'antd';

const FormItem = Form.Item;

interface PropsType {
  label: string;
  name: string;
  initialValue?: any;
  itemLayout?: {};
  rules?: object[];
  size?: string;
  placeholder?: string;
  options: any;
  loadData: () => void;
  getPopupContainer: () => void;
  getFieldDecorator?:any;
  count?:number;
}

const CascaderItem: React.FC<PropsType> = props => {
  const {
    label,
    name,
    initialValue,
    // 不定义默认值，否则在form中定义后，form中的itemLayout不生效，此处会把form中的覆盖掉
    // 此处在form中统一处理，如果需要覆盖则在引用此组件处进行定义
    // itemLayout={
    //   labelCol: { span: 4 },
    //   wrapperCol: { span: 14 },
    itemLayout={},
    // },
    rules,
    getFieldDecorator,
    options,
    count,
    ...othersProps
  } = props;

  return (
    <FormItem label={label} {...itemLayout} hasFeedback={!!rules}>
      {getFieldDecorator(name, {
        initialValue,
        rules,
      })(<Cascader options={options} {...othersProps} />)}
    </FormItem>
  );
};
export default CascaderItem;

